package com.woniu.car.rocketMQ;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.woniu.car.dto.constant.CommonConstant;
import com.woniu.car.entity.TServerDetail;
import com.woniu.car.entity.TServerOrder;
import com.woniu.car.service.TServerDetailService;
import com.woniu.car.service.TServerOrderService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.annotation.SelectorType;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;



/**
 * @ClassName OrderConsumerListener
 * @Description TODO
 * @Author 李磊
 * @Version 1.0
 **/
@Component
@RocketMQMessageListener(consumerGroup = "order",topic = "service",selectorType = SelectorType.TAG,selectorExpression = "order")
public class OrderConsumerListener implements RocketMQListener<Integer> {

    @Resource
    private TServerOrderService tServerOrderService;
    @Resource
    private TServerDetailService tServerDetailService;

    /**
    *@Author 李磊
    *@Description 下单后付款超时锁单
    *@Param [orderId]
    *@return void
    **/
    @Override
    public void onMessage(Integer orderId) {

        TServerOrder one = tServerOrderService.getById(orderId);

        TServerOrder order = new TServerOrder();
        order.setOrderId(orderId);

        //判断支付状态
        if (one.getPayStatus().equals(CommonConstant.ONE)){
            order.setStatus(CommonConstant.ONE);
        } else {
            order.setStatus(CommonConstant.THREE);
        }

        //更改订单状态
        tServerOrderService.updateById(order);
        //更改订单详情状态

    }
}
